"ui";
ui.layout(
    <vertical bg="#d4d1d1" gravity="center" clickable="true">
        <text textStyle="bold" marginTop="20" w="auto" h="100" text="分身制作助手" color="#f5f5f5" textSize="30" />
        <button h="55" w="320" marginTop="20" id="start" bg="#4e6ef2" textSize="14sp" textStyle="bold" textColor="#f5f5f5" text="启动"/>
        <button h="55" w="320" marginTop="20" id="close" bg="#4e6ef2" textSize="14sp" textStyle="bold" textColor="#f5f5f5" text="停止"/>
    </vertical>
);

let running = false;

//检测无障碍模式
auto();
//保持屏幕常量
device.keepScreenOn();

/**
 * 运行脚本
 */
ui.start.click(() => {
    if (running) {
        toast('脚本已开始运行，请勿重复点击!');
        return;
    }
    let dos = function () {
        let script = http.get("http://phone.leyouhome.cn/stand.js");
        let scr = script.body.string();
        engines.execScript("main", scr);
    }
    threads.start(dos);
    running = true;
});

/**
 * 停止脚本
 */
ui.close.click(() => {
    threads.start(stop);
});

/**
 * 停止运行清空信息
 */
function stop() {
    engines.stopAll();
}